# Definition for a binary tree node.
import collections
import queue
from typing import Optional


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution:
    def isEvenOddTree(self, root: Optional[TreeNode]) -> bool:
        q = collections.deque()
        flag = -1
        if root:
            q.append(root)

        while len(q):
            n = len(q)
            # print(n)
            flag += 1
            num_s = []
            while n:
                node: TreeNode = q.popleft()

                if flag % 2 == 1 and node.val % 2 == 1:
                    return False
                if flag % 2 == 0 and node.val % 2 == 0:
                    return False

                if len(num_s) == 0:
                    num_s.append(node.val)
                else:
                    if flag % 2 == 1 and node.val >= num_s[-1]:
                        return False
                    if flag % 2 == 0 and node.val <= num_s[-1]:
                        return False
                    num_s.append(node.val)

                if node.left:
                    q.append(node.left)
                if node.right:
                    q.append(node.right)

                n -= 1

        return True


def stringToTreeNode(input):
    input = input.strip()
    input = input[1:-1]
    if not input:
        return None

    inputValues = [s.strip() for s in input.split(',')]
    root = TreeNode(int(inputValues[0]))
    nodeQueue = [root]
    front = 0
    index = 1
    while index < len(inputValues):
        node = nodeQueue[front]
        front = front + 1

        item = inputValues[index]
        index = index + 1
        if item != "null":
            leftNumber = int(item)
            node.left = TreeNode(leftNumber)
            nodeQueue.append(node.left)

        if index >= len(inputValues):
            break

        item = inputValues[index]
        index = index + 1
        if item != "null":
            rightNumber = int(item)
            node.right = TreeNode(rightNumber)
            nodeQueue.append(node.right)
    return root


def main():
    import sys
    import io
    def readlines():
        for line in io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8'):
            yield line.strip('\n')

    lines = readlines()
    while True:
        try:
            line = next(lines)
            root = stringToTreeNode(line);

            ret = Solution().isEvenOddTree(root)

            out = (ret);
            print(out)
        except StopIteration:
            break


if __name__ == '__main__':
    main()
